package com.qfedu.knowledge.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.knowledge.dao.QuestionWrongDao;
import com.qfedu.knowledge.entity.bo.QuestionWrongBO;
import com.qfedu.knowledge.entity.dto.BasePageDTO;
import com.qfedu.knowledge.entity.dto.BatchWrongDTO;
import com.qfedu.knowledge.entity.dto.WrongDTO;
import com.qfedu.knowledge.entity.vo.PageResult;
import com.qfedu.knowledge.entity.vo.WrongVO;
import com.qfedu.knowledge.service.IQuestionWrongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName QuestionWrongServiceImpl
 * @Author ykx
 * @Date 2024/4/29 18:29
 * @Version 1.0
 */
@Service
public class QuestionWrongServiceImpl extends ServiceImpl<QuestionWrongDao, QuestionWrongBO> implements IQuestionWrongService {

    @Autowired
    private QuestionWrongDao questionWrongDao;

    @Override
    public Boolean insert(WrongDTO wrongDTO) {
        QuestionWrongBO questionWrongBO = new QuestionWrongBO();
        questionWrongBO.setQuestionId(wrongDTO.getQuestionId());
        questionWrongBO.setRemark(wrongDTO.getRemark());
        return save(questionWrongBO);
    }

    @Override
    public Boolean batchInsert(BatchWrongDTO batchWrongDTO) {
        List<QuestionWrongBO> questionWrongBOS = new ArrayList<>();
        for (int i = 0; i < batchWrongDTO.getQuestionIdList().size(); i++) {
            QuestionWrongBO questionWrongBO = new QuestionWrongBO();
            questionWrongBO.setQuestionId(batchWrongDTO.getQuestionIdList().get(i));
            questionWrongBO.setRemark(batchWrongDTO.getRemark());
            questionWrongBOS.add(questionWrongBO);
        }
        return saveBatch(questionWrongBOS);
    }

    @Override
    public PageResult<WrongVO> getWrongList(BasePageDTO basePageDTO) {
        PageHelper.startPage(basePageDTO.getPage(), basePageDTO.getSize());
        return new PageResult<>(new PageInfo<>(questionWrongDao.getWrongList()));
    }
}
